package messages;

import static org.junit.Assert.*;

import org.junit.Test;

public class CStringTest {

	@Test
	public void testParse() {
		
		byte[] data = new byte[] { 'I', ' ', 'a', 'm', ' ', 'a', ' ', 'b', 'a', 'n', 'a', 'n', 'a', '!', 0};
		
		CString str = new CString(data, 0);
		
		assertEquals(15, str.getLength());
		
		assertEquals("I am a banana!", str.toString());
		
		data = new byte[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 0};
		
		str = new CString(data, 2);
		assertEquals(8, str.getLength());
		assertEquals("CDEFGHI", str.toString());
		
		data = new byte[] { 0, 'A', 0};
		str = new CString(data, 0);
		assertEquals(1, str.getLength());
		assertEquals("", str.toString());
		
	}
	
	@Test
	public void testAddToByteArray()
	{
		ByteList list = new ByteList();
		
		CString str = new CString("sweet");
		
		str.appendToByteList(list);
		
		byte[] result = list.toByteArray();
		assertEquals(6, result.length);
		
		assertEquals('s', result[0]);
		assertEquals('w', result[1]);
		assertEquals('e', result[2]);
		assertEquals('e', result[3]);
		assertEquals('t', result[4]);
		assertEquals(0, result[5]);
		
	}

}
